package com.offcn.sellergood.controller;
import com.offcn.sellergood.entity.SpecificationEntity;
import com.offcn.sellergood.pojo.Specification;
import com.offcn.sellergood.service.SpecificationService;
import com.offcn.entity.PageResult;
import com.offcn.entity.Result;
import com.offcn.entity.StatusCode;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/****
 * @Author:ujiuye
 * @Description:
 * @Date 2021/2/1 14:19
 *****/
@Api(tags = "SpecificationController")
@RestController
@RequestMapping("/specification")
@CrossOrigin
public class SpecificationController {

    @Autowired
    private SpecificationService specificationService;

    @PostMapping
    public Result add(@RequestBody SpecificationEntity entity){
        specificationService.add(entity);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    @GetMapping("/{id}")
    public Result getById1(@PathVariable Long id){
        SpecificationEntity entity = specificationService.findById(id);
        return new Result(true,StatusCode.OK,"查询成功",entity);
    }

    @PutMapping("/{id}")
    public Result update1(@RequestBody SpecificationEntity entity,@PathVariable Long id){
        entity.getSpecification().setId(id); //定位到修改的数据
        specificationService.update(entity);
        return new Result(true, StatusCode.OK,"修改成功");
    }
    @DeleteMapping("/{id}")
    public Result deleteBy(@PathVariable Long id){
        specificationService.deleteBy(id);
        return new Result(true, StatusCode.OK,"删除成功");
    }
}
